package com.ruoyi.settled.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.settled.domain.SalesOrderCost;
import com.ruoyi.settled.service.ISalesOrderCostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成本核算Controller
 * 
 * @author huangchen
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/settled/cost")
public class SalesOrderCostController extends BaseController
{
    @Autowired
    private ISalesOrderCostService salesOrderCostService;

    /**
     * 查询成本核算列表
     */
    @PreAuthorize("@ss.hasPermi('settled:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalesOrderCost salesOrderCost)
    {
        startPage();
        List<SalesOrderCost> list = salesOrderCostService.selectSalesOrderCostList(salesOrderCost);
        return getDataTable(list);
    }

    /**
     * 导出成本核算列表
     */
    @PreAuthorize("@ss.hasPermi('settled:cost:export')")
    @Log(title = "成本核算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalesOrderCost salesOrderCost)
    {
        List<SalesOrderCost> list = salesOrderCostService.selectSalesOrderCostList(salesOrderCost);
        ExcelUtil<SalesOrderCost> util = new ExcelUtil<SalesOrderCost>(SalesOrderCost.class);
        util.exportExcel(response, list, "成本核算数据");
    }

    /**
     * 获取成本核算详细信息
     */
    @PreAuthorize("@ss.hasPermi('settled:cost:query')")
    @GetMapping(value = "/{costId}")
    public AjaxResult getInfo(@PathVariable("costId") Long costId)
    {
        return success(salesOrderCostService.selectSalesOrderCostByCostId(costId));
    }

    /**
     * 新增成本核算
     */
    @PreAuthorize("@ss.hasPermi('settled:cost:add')")
    @Log(title = "成本核算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalesOrderCost salesOrderCost)
    {
        return toAjax(salesOrderCostService.insertSalesOrderCost(salesOrderCost));
    }

    /**
     * 修改成本核算
     */
    @PreAuthorize("@ss.hasPermi('settled:cost:edit')")
    @Log(title = "成本核算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalesOrderCost salesOrderCost)
    {
        return toAjax(salesOrderCostService.updateSalesOrderCost(salesOrderCost));
    }

    /**
     * 删除成本核算
     */
    @PreAuthorize("@ss.hasPermi('settled:cost:remove')")
    @Log(title = "成本核算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costIds}")
    public AjaxResult remove(@PathVariable Long[] costIds)
    {
        return toAjax(salesOrderCostService.deleteSalesOrderCostByCostIds(costIds));
    }
}
